package com.hippo.core.pojo.vo.result;

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;

/**
 * @ClassName BaseResult
 * @Description TODO 基础统一返回实体类
 * @Author tangxl
 * @create 2023-04-03 08:39
 **/
@Data
@Schema(name = "基础统一返回实体类")
public class BaseResult<T> {
    public static final int OK_CODE = 200;
    public static final int FAIL_CODE = 500;

    @Schema(name = "状态码", example = "200")
    private int code;
    @Schema(name = "消息", example = "成功")
    private String msg;
    @Schema(name = "数据")
    private T data;

    public BaseResult() {
        this.code = OK_CODE;
        this.msg = "成功";
    }

    public BaseResult(T data) {
        this.code = OK_CODE;
        this.msg = "成功";
        this.data = data;
    }

    public BaseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseResult(String msg,T data) {
        this.code = OK_CODE;
        this.msg = msg;
        this.data = data;
    }

    public BaseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static BaseResult ok() {
        return new BaseResult();
    }

    public static <T> BaseResult ok(T data) {
        return new BaseResult(data);
    }

    public static BaseResult ok(String msg) {
        return new BaseResult(OK_CODE, msg);
    }

    public static BaseResult ok(int code, String msg) {
        return new BaseResult(code, msg);
    }
    public static <T> BaseResult ok(String msg, T data) {
        return new BaseResult(msg, data);
    }

    public static BaseResult ok(int code, String msg, Object data) {
        return new BaseResult(code, msg, data);
    }

    public static BaseResult fail() {
        return new BaseResult(FAIL_CODE, "失败");
    }

    public static BaseResult fail(String msg) {
        return new BaseResult(FAIL_CODE, msg);
    }

    public static BaseResult fail(int code, String msg) {
        return new BaseResult(code, msg);
    }

    public static BaseResult fail(int code, String msg, Object data) {
        return new BaseResult(code, msg, data);
    }


}
